// cd /projects/data_commons/cw_code/
// qstata cw_ind_fk_2_comp.do &

global dir_proj = "/projects/data_commons/"
global dir_cw = "${dir_proj}/cw/"
global dir_lbd = "${dir_proj}/lbd/"

di "Started at $S_DATE $S_TIME"

//==============================================================================
// Take a look how different versions of fk_naics differ

use "${dir_lbd}/lbd_raw_sum_fk_comp.dta", clear

// Mark difference between fk_naics
gen fk_d0207 = 1 if fk02 != fk07
gen fk_d0212 = 1 if fk02 != fk12
gen fk_d0712 = 1 if fk07 != fk12

foreach iver in 02 07 12 {
	gen fk_naics = fk`iver'
	merge m:1 fk_naics using ${dir_cw}/cw_ind_fk_imp, keep(match master) gen(m_fk`iver')
	tab fk_naics ch_ind if m_fk`iver' != 3
	drop fk_naics
	rename ch_ind ch_ind_`iver'
}

// Mark difference between assigned industries
gen ch_ind_d0207 = 1 if ch_ind_02 != ch_ind_07
gen ch_ind_d0212 = 1 if ch_ind_02 != ch_ind_12
gen ch_ind_d0712 = 1 if ch_ind_07 != ch_ind_12

// Select comparison to make
if 0 {
	
// Compare fk

keep if year <= 2009
collapse (sum) emp est pay, by(year fk_d0207)

keep if year <= 2009
collapse (sum) emp est pay, by(year fk_d0212)

keep if year <= 2014
collapse (sum) emp est pay, by(year fk_d0712)

// Compare assigned ind

keep if year <= 2009
collapse (sum) emp est pay, by(year ch_ind_d0207)

keep if year <= 2009
tab fk12 if ch_ind_12 == .
drop if ch_ind_12 == .
collapse (sum) emp est pay, by(year ch_ind_d0212)

keep if year <= 2014
tab fk12 if ch_ind_12 == .
drop if ch_ind_12 == .
collapse (sum) emp est pay, by(year ch_ind_d0712)

}

di "Ended at $S_DATE $S_TIME"
// End of do file
